﻿package  
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	/**
	 * ...
	 * 所谓类绑定剪辑,就当作为该剪辑写一个文档类,文档类中的this指向该剪辑
	 * @author chancidal
	 */
	public class MyButtonBase extends MovieClip
	{
		//
		private var m_labels:Array = ["over", "down", "out"];
		//
		public function MyButtonBase() 
		{
			this.stop();
			init();
		}
		private function init():void {
			addEventListener(MouseEvent.MOUSE_DOWN, dragButton);
			addEventListener(MouseEvent.ROLL_OVER, rollOver);
			addEventListener(MouseEvent.ROLL_OUT, rollOut);
		}
		private function dragButton(evt:MouseEvent):void {
			this.parent.addChildAt(this, this.parent.numChildren - 1);
			this.startDrag();
			for (var i:int = 0; i < m_labels.length; i++) {
				if (m_labels[i] == "down") {
					this.gotoAndStop("down");
				}
			}
			addEventListener(MouseEvent.MOUSE_UP, stopDragButton);
		}
		private function stopDragButton(evt:MouseEvent):void {
			this.stopDrag();
			for (var i:int = 0; i < m_labels.length; i++) {
				if (m_labels[i] == "over") {
					this.gotoAndStop("over");
				}
			}
			removeEventListener(MouseEvent.MOUSE_UP, stopDragButton);
		}
		private function rollOver(evt:MouseEvent):void {
			for (var i:int = 0; i < m_labels.length; i++) {
				if (m_labels[i] == "over") {
					this.gotoAndStop("over");
				}
			}
		}
		private function rollOut(evt:MouseEvent):void {
			for (var i:int = 0; i < m_labels.length; i++) {
				if (m_labels[i] == "out") {
					this.gotoAndStop("out");
				}
			}
		}
	}

}